import requests, json
from jsonpath import jsonpath


proxies = {
    'http': '127.0.0.1:10809',
    'https': '127.0.0.1:10809',
}
headers = {
    "Accept": "application/json",
    "X-API-KEY": "7b952a836b484c5e84e8171757aa69f0"
}
data_cursor = ''
data_suple = set()
while True:
    url = f"https://api.opensea.io/api/v1/events?asset_contract_address=0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d&occurred_after=1656518400&cursor={data_cursor}"
    response = requests.get(url, headers=headers, proxies=proxies)
    response_data = json.loads(response.text)
    print(response_data)
    data_cursor = jsonpath(response_data, '$..next')[0]
    token_id = jsonpath(response_data, '$..token_id')

    if token_id == False:
        continue
    # token_id = jsonpath(json.loads(response.text), '$..token_id')[i]
    # data_suple.add(False)
    data_suple.update(token_id)

    # data_suple = token_id[i] + token_id[i+1]
    # print(token_id)
    # print(data_suple)
    print(len(data_suple))
    if data_cursor == 'null':
        print('已全部打印完成')
        break
    # print(response.status_code)
    # print(response.text)
    # with open('./events.json', 'a') as file:
    #     file.write(response.text)
    #     if data_cursor == 'null':
    #         break
# print(data_suple)
# print(len(data_suple))